﻿using System;
using System.Linq;
using System.Web.Mvc;
using Citi.Scheduler.Domain;
using Citi.Scheduler.WebUi.Models;

namespace Citi.Scheduler.WebUi.Controllers
{
    public class UserController : ControllerBase<UserModel, User>
    {
        public ActionResult Index()
        {
            return IndexBase(true);
        }

        public ActionResult Form()
        {
            return View();
        }

        [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
        public ActionResult ActionForm(int? id)
        {
            return ActionBase(id, true);
        }

        [HttpPost]
        public ActionResult ActionForm(UserModel model)
        {
            return ActionBase(model, true);
        }

        public ActionResult Delete(int id)
        {
            return DeleteBase(id, true);
        }

        public void FillViewBag(int? managerId = null)
        {
            var users = new User().SelectAllActive<User>().OrderBy(m => m.Name);
            ViewBag.Managers = users.ToSelectList(x => x.Name, x => x.Id.ToString(), "Select an user",
                managerId.HasValue ? managerId.Value.ToString() : string.Empty);
        }
    }
}
